
class Context {
    public int Level;
    public State State;

    public Context(int level){
        this.Level=level;
    }

    public void setState(State state) {
        this.State = state;
    }

    public void show() {
        State.show(this);
    }
}

public abstract class State {
    public static void main(String[] args) {
        Context ctx = new Context(1);
        ctx.setState(new StateA());
        ctx.show();
        ctx.Level = 2;
        ctx.show();
        ctx.Level = 3;
        ctx.show();
    }
    public abstract void show(Context context);
}

class StateA extends State {
    @Override
    public void show(Context context) {
        if (context.Level == 1) {
            System.out.println(String.format("StateA.show({0})", context.Level));
        } else {
            context.State = new StateB();
            context.show();
        }
    }
}

class StateB extends State {
    @Override
    public void show(Context context) {
        if (context.Level == 2) {
            System.out.println(String.format("StateB.show({0})", context.Level));
        } else {
            context.State = new StateC();
            context.show();
        }
    }
}

class StateC extends State {
    @Override
    public void show(Context context) {
        System.out.println(String.format("StateC.show({0})", context.Level));
    }
}